package com.miaoxun.domain.param;

import java.io.Serializable;

/**
 * base param
 */
public class BaseParam implements Serializable {
    private int limit;//页数
    private int offset;//第n页
    private String order = "";
    private String sort = "";

    public BaseParam() {
    }

    public BaseParam(int limit, int offset, String order, String sort) {

        this.limit = limit;
        this.offset = offset;
        this.order = order;
        this.sort = sort;
    }

    public int getLimit() {
        if (limit <= 0)
            return 10;
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public int getOffset() {
        if (offset <= 0)
            return 1;
        return offset / getLimit() + 1;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }

    public String getOrder() {
        if (order == null)
            return "";
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public String getSort() {

        if (getOrder() == null || "".equalsIgnoreCase(getOrder()))
            return "";

        if (sort == null || sort.length() == 0)
            return "";
        if ("desc".equalsIgnoreCase(sort))
            return "DESC";
        if ("asc".equalsIgnoreCase(sort))
            return "ASC";
        return "";
    }

    public void setSort(String sort) {
        this.sort = sort;
    }
}
